﻿using System;
using System.Windows.Forms;
using WindowsAPI.Windows;

namespace Test_Form
{
    public partial class AttachInputTestForm : Form
    {
        private readonly Window f_CalculatorWindow = Window.GetWindow("Калькулятор");
        private Window f_CurrentWindow;

        public AttachInputTestForm()
        {
            InitializeComponent();
        }

        private void AttachInputTestForm_Load(object sender, EventArgs e)
        {
            if(!f_CalculatorWindow.IsExist) { Close(); return; }

            f_CalculatorWindow.AttachThreadInput(true);
        }

        private void AttachInputTestForm_Shown(object sender, EventArgs e)
        {
            f_CurrentWindow = this;

            Focus();
        }

        private int i1;
        private void AttachInputTestForm_Deactivate(object sender, EventArgs e)
        {
            label1.Text = (++i1).ToString();
            var result = f_CurrentWindow.SetWindowPos(InsertAfterEnum.Top, 0, 0, 0, 0,
                                                     SetWindowPosFlags.IgnoreResize | SetWindowPosFlags.IgnoreMove);
            label2.Text = result.ToString();
        }
    }
}
